<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    class Person{
      //创建实例一定会执行构造方法，但可以不写
      constructor(name,age){
        this.name=name
        this.age=age
        console.log('构造函数');
      }
      //跟实例共享方法
      eat(){
        console.log('人eat');
      }
    }
    const p=new Person('a',18)
    const p1=new Person('b',19)
    console.log(p.eat===p1.eat);
    //表达式创建类
    const people=class {
      constructor(){}
      eat(){}
    }
    const pp=new people()
    //函数创建类
    function Dog(name,age){
      this.name=name
      this.age=age
    }
    Dog.prototype.eat=function(){
      console.log('狗eat');
    }
    const d=new Dog('lucky',2)
    console.log(d);
    d.eat()
    //立即执行的类
    new (class{
      constructor(){
        console.log('constructor');
      }
    })()
  </script>
</body>
</html>